using System;
using System.Xml;
using System.Xml.Xsl;
using System.IO;
using System.Xml.XPath;

namespace BTSProjectWizard.FileGenerators
{
    
	/// <summary>
	/// This class will take an input file - run it as an xslt
	/// The symbols added to the Wizard during the execution stage will
	/// be available
	/// </summary>
	public class XSLTFileGenerator : IBTWizardFileGen
	{
		
		public void AddFile(string path,EnvDTE.Project proj,Wizard wiz,string suggestedName)
		{
			string newfile = null;
			newfile = Path.GetTempFileName();//
			string newfilename = Path.Combine(Path.GetDirectoryName(proj.FullName),Path.GetFileName(path));
			//XslTransform t = new XslTransform();
            XslCompiledTransform t = new XslCompiledTransform();
            
			t.Load(path);
           
			XmlDocument dummy = new XmlDocument();
			dummy.LoadXml("<s:doc xmlns:s='http://Schema1'></s:doc>");
			FileStream fs = File.OpenWrite(newfile);
			XsltArgumentList al = new XsltArgumentList();
			al.AddExtensionObject("http://wiz",wiz);
			//t.Transform(dummy,al,fs,null);
            t.Transform(dummy, al, fs);
			fs.Close();
			File.Copy(newfile,newfilename);
			proj.ProjectItems.AddFromFile(newfilename);
			
			
		}



        #region IBTWizardFileGen Members

        public bool Init(XmlAttribute[] Attributes, Wizard wiz)
        {
            return true;
        }

        #endregion
    }
}
